<?php
include_once("admin_common.inc.php");
include_once(_INC_PATH.'database.php');
include_once(_INC_PATH.'page.inc.php');
checkAdmin();
class AdminBase{
	var $db;
	var $smarty;
	
	function adminBase(){
		global $smarty, $permissionCfg;
		$this->db = new database();
		$this->smarty = $smarty;

		if(!empty($_REQUEST['method'])){
			if(method_exists($this,$_REQUEST['method'])){
				if($this->checkFunPermission($_REQUEST['method'])){
					$method = $_REQUEST['method'];
				}
			}
		}
		$method = empty($method)?'index':$method;
		$this->$method();
	}
	
	/*
	//记录管理员ID及操作时间
	//$id:可以是id号或id数组   $dbname:表名 
	*/
	function managerLog($id, $dbname){
		$manager_id = $_SESSION['admin_login']['id'];
		$time = date("Y-m-d H:i:s");
		if(is_array($id) && count($id) > 0){
			foreach($id as $key=>$value){
				$sql = "update $dbname set update_time='$time',manager_id='$manager_id' where id='$value'";
				$this->db->query($sql);
			}
		}elseif(intval($id) > 0){
			$sql = "update $dbname set update_time='$time',manager_id='$manager_id' where id='$id'";
			$this->db->query($sql);
		}
		
	}
	
	/*
	判断是否有该方法的权限
	*/
	function checkFunPermission($funName){
		global $permissionCfg;
		$grade = intval($_SESSION['admin_login']['grade']);
		if($grade > 1){
			$temp_arr = explode("/",$_SERVER['PHP_SELF']);
			$phpName = end($temp_arr);
			$funArr = $permissionCfg[$grade][$phpName];
			if(in_array($funName, $funArr)){
				return true;
			}else{
				$_SESSION['sysMsg'] = '无此权限';
				return false;
			}
		}else{
			return true;
		}
	}

	/*
	获取企业信息
	*/
	function getCorInfo()
	{
		$id = intval($_POST['id']);
		if($id > 0){
			$sql = "select * from tbl_corporation where del_flg='0' and id='$id'";
			$row = $this->db->loadRow($sql);
			if(!empty($row)){
				echo json_encode($row);die;
			}else{
				echo 'no data';die;
			}
		}else{
			echo 'no id';die;
		}
	}
	
}

?>